package com.wclass.mapper;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.wclass.entity.CouresTask;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.RowBounds;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 课程作业 Mapper 接口
 * </p>
 *
 * @author 张浩高
 * @since 2018-12-20
 */
public interface CouresTaskMapper extends BaseMapper<CouresTask> {


    /**
     * <p>
     * 根据 entity 条件，查询全部记录（并翻页）
     * </p>
     *
     * @param rowBounds 分页查询条件（可以为 RowBounds.DEFAULT）
     * @param wrapper   实体对象封装操作类（可以为 null）
     * @return List<T>
     */
    @Override
    @Select("select distinct info.*,appUser.picture_address,appUser.nick_name ${ew.sqlSelect} from coures_task as info " +
            "left join base_app_user as appUser on info.user_id=appUser.id " +
            "left join coures_task as stuTask on info.id=stuTask.p_id " +
            "where info.state=0 and appUser.state=0 ${ew.sqlSegment}")
    List<CouresTask> selectPage(RowBounds rowBounds, @Param("ew") Wrapper<CouresTask> wrapper);

    /**
     * <p>
     * 根据 entity 条件，查询全部记录
     * </p>
     *
     * @param wrapper 实体对象封装操作类（可以为 null）
     * @return List<T>
     */
    @Override
    @Select("select info.*,appUser.picture_address,appUser.nick_name ${ew.sqlSelect} from coures_task as info left " +
            "join base_app_user as appUser  on info.user_id=appUser.id where appUser.state=0 ${ew.sqlSegment}")
    List<CouresTask> selectList(@Param("ew") Wrapper<CouresTask> wrapper);

    /**
     * <p>
     * 根据 ID 查询
     * </p>
     *
     * @param id 主键ID
     * @return T
     */
    @Override
    @Select("select info.*,appUser.picture_address,appUser.nick_name from coures_task as info left " +
            "join base_app_user as appUser  on info.user_id=appUser.id where appUser.state=0 and info.id=#{id}")
    CouresTask selectById(@Param("id") Serializable id);

    @Select("select distinct count(1) from coures_task as info " +
            "left join base_app_user as appUser on info.user_id=appUser.id " +
            "left join coures_task as stuTask on info.id=stuTask.p_id " +
            "where info.state=0 and appUser.state=0 ${ew.sqlSegment}")
    Integer selectTaskCount(@Param("ew") Wrapper<CouresTask> wrapper);
}
